// Created from GenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Reflection;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.Generated.AbstractMessage;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using TX = System.String;
using FT = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class CCR_I16 : AbstractMessage
    {
		/// Constructor
		public CCR_I16() : base()
        {
			if (MSH != null) {
                MSH.MessageType = new MSG() { MessageCode = "CCR", TriggerEvent = "I16" };
			}
        }

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("SFT",2)]
  	    [HL7Field(HL7Version.v27, 2, HL7Repeat.True, HL7Required.False,"SFT")]
	    public SFT[] SFT {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("UAC",3)]
  	    [HL7Field(HL7Version.v27, 3, HL7Repeat.False, HL7Required.False,"UAC")]
	    public UAC UAC {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("RF1",4)]
  	    [HL7Field(HL7Version.v27, 4, HL7Repeat.True, HL7Required.True,"RF1")]
	    public RF1[] RF1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("PROVIDER_CONTACT",5)]
  	    [HL7Field(HL7Version.v27, 5, HL7Repeat.True, HL7Required.True,"PROVIDER_CONTACT_CCR_I16")]
	    public PROVIDER_CONTACT_CCR_I16[] PROVIDER_CONTACT {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("CLINICAL_ORDER",9)]
  	    [HL7Field(HL7Version.v27, 9, HL7Repeat.True, HL7Required.False,"CLINICAL_ORDER_CCR_I16")]
	    public CLINICAL_ORDER_CCR_I16[] CLINICAL_ORDER {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("PATIENT",31)]
  	    [HL7Field(HL7Version.v27, 31, HL7Repeat.True, HL7Required.True,"PATIENT_CCR_I16")]
	    public PATIENT_CCR_I16[] PATIENT {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("NK1",35)]
  	    [HL7Field(HL7Version.v27, 35, HL7Repeat.True, HL7Required.False,"NK1")]
	    public NK1[] NK1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("INSURANCE",36)]
  	    [HL7Field(HL7Version.v27, 36, HL7Repeat.True, HL7Required.False,"INSURANCE_CCR_I16")]
	    public INSURANCE_CCR_I16[] INSURANCE {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("APPOINTMENT_HISTORY",41)]
  	    [HL7Field(HL7Version.v27, 41, HL7Repeat.True, HL7Required.False,"APPOINTMENT_HISTORY_CCR_I16")]
	    public APPOINTMENT_HISTORY_CCR_I16[] APPOINTMENT_HISTORY {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("CLINICAL_HISTORY",61)]
  	    [HL7Field(HL7Version.v27, 61, HL7Repeat.True, HL7Required.False,"CLINICAL_HISTORY_CCR_I16")]
	    public CLINICAL_HISTORY_CCR_I16[] CLINICAL_HISTORY {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("PATIENT_VISITS",103)]
  	    [HL7Field(HL7Version.v27, 103, HL7Repeat.True, HL7Required.True,"PATIENT_VISITS_CCR_I16")]
	    public PATIENT_VISITS_CCR_I16[] PATIENT_VISITS {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("MEDICATION_HISTORY",107)]
  	    [HL7Field(HL7Version.v27, 107, HL7Repeat.True, HL7Required.False,"MEDICATION_HISTORY_CCR_I16")]
	    public MEDICATION_HISTORY_CCR_I16[] MEDICATION_HISTORY {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("PROBLEM",128)]
  	    [HL7Field(HL7Version.v27, 128, HL7Repeat.True, HL7Required.False,"PROBLEM_CCR_I16")]
	    public PROBLEM_CCR_I16[] PROBLEM {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("GOAL",143)]
  	    [HL7Field(HL7Version.v27, 143, HL7Repeat.True, HL7Required.False,"GOAL_CCR_I16")]
	    public GOAL_CCR_I16[] GOAL {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("PATHWAY",158)]
  	    [HL7Field(HL7Version.v27, 158, HL7Repeat.True, HL7Required.False,"PATHWAY_CCR_I16")]
	    public PATHWAY_CCR_I16[] PATHWAY {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
        [PropertyClassification("REL",173)]
  	    [HL7Field(HL7Version.v27, 173, HL7Repeat.True, HL7Required.False,"REL")]
	    public REL[] REL {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override Stack<string> ConsumeTextSegments(Stack<string> availableData, HL7ParserOptions options) {

				if (HL7Version.v27 == options.Version) {
		 SFT = PopSegmentParseAndCheckRequiredArray<SFT>(availableData, options, "SFT");
		 UAC = PopSegmentParseAndCheckRequired<UAC>(availableData, options, "UAC");
		 RF1 = PopSegmentParseAndCheckRequiredArray<RF1>(availableData, options, "RF1");
		 PROVIDER_CONTACT = ProcessGroupArray<PROVIDER_CONTACT_CCR_I16>(availableData, options, "PROVIDER_CONTACT");
		 CLINICAL_ORDER = ProcessGroupArray<CLINICAL_ORDER_CCR_I16>(availableData, options, "CLINICAL_ORDER");
		 PATIENT = ProcessGroupArray<PATIENT_CCR_I16>(availableData, options, "PATIENT");
		 NK1 = PopSegmentParseAndCheckRequiredArray<NK1>(availableData, options, "NK1");
		 INSURANCE = ProcessGroupArray<INSURANCE_CCR_I16>(availableData, options, "INSURANCE");
		 APPOINTMENT_HISTORY = ProcessGroupArray<APPOINTMENT_HISTORY_CCR_I16>(availableData, options, "APPOINTMENT_HISTORY");
		 CLINICAL_HISTORY = ProcessGroupArray<CLINICAL_HISTORY_CCR_I16>(availableData, options, "CLINICAL_HISTORY");
		 PATIENT_VISITS = ProcessGroupArray<PATIENT_VISITS_CCR_I16>(availableData, options, "PATIENT_VISITS");
		 MEDICATION_HISTORY = ProcessGroupArray<MEDICATION_HISTORY_CCR_I16>(availableData, options, "MEDICATION_HISTORY");
		 PROBLEM = ProcessGroupArray<PROBLEM_CCR_I16>(availableData, options, "PROBLEM");
		 GOAL = ProcessGroupArray<GOAL_CCR_I16>(availableData, options, "GOAL");
		 PATHWAY = ProcessGroupArray<PATHWAY_CCR_I16>(availableData, options, "PATHWAY");
		 REL = PopSegmentParseAndCheckRequiredArray<REL>(availableData, options, "REL");
		}
			if (availableData != null && availableData.Count > 0) {
				ConsumeZSegmentsFromText(availableData, options);
			}
            return availableData;
        
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "CCR_I16";
			}
        }

        static CCR_I16() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(CCR_I16));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
			if (MSH != null) {
				segmentData.Add(MSH.GetER7(options));
			}
			if (SFT != null && SFT.Length > 0) {
				for (int i = 0; i < SFT.Length; i++) {
					segmentData.Add(SFT[i].GetER7(options));
				}
			}
			if (UAC != null) {
				segmentData.Add(UAC.GetER7(options));
			}
			if (RF1 != null && RF1.Length > 0) {
				for (int i = 0; i < RF1.Length; i++) {
					segmentData.Add(RF1[i].GetER7(options));
				}
			}
			if (PROVIDER_CONTACT != null && PROVIDER_CONTACT.Length > 0) {
				for (int i = 0; i < PROVIDER_CONTACT.Length; i++) {
					segmentData.Add(PROVIDER_CONTACT[i].GetER7(options));
				}
			}
			if (CLINICAL_ORDER != null && CLINICAL_ORDER.Length > 0) {
				for (int i = 0; i < CLINICAL_ORDER.Length; i++) {
					segmentData.Add(CLINICAL_ORDER[i].GetER7(options));
				}
			}
			if (PATIENT != null && PATIENT.Length > 0) {
				for (int i = 0; i < PATIENT.Length; i++) {
					segmentData.Add(PATIENT[i].GetER7(options));
				}
			}
			if (NK1 != null && NK1.Length > 0) {
				for (int i = 0; i < NK1.Length; i++) {
					segmentData.Add(NK1[i].GetER7(options));
				}
			}
			if (INSURANCE != null && INSURANCE.Length > 0) {
				for (int i = 0; i < INSURANCE.Length; i++) {
					segmentData.Add(INSURANCE[i].GetER7(options));
				}
			}
			if (APPOINTMENT_HISTORY != null && APPOINTMENT_HISTORY.Length > 0) {
				for (int i = 0; i < APPOINTMENT_HISTORY.Length; i++) {
					segmentData.Add(APPOINTMENT_HISTORY[i].GetER7(options));
				}
			}
			if (CLINICAL_HISTORY != null && CLINICAL_HISTORY.Length > 0) {
				for (int i = 0; i < CLINICAL_HISTORY.Length; i++) {
					segmentData.Add(CLINICAL_HISTORY[i].GetER7(options));
				}
			}
			if (PATIENT_VISITS != null && PATIENT_VISITS.Length > 0) {
				for (int i = 0; i < PATIENT_VISITS.Length; i++) {
					segmentData.Add(PATIENT_VISITS[i].GetER7(options));
				}
			}
			if (MEDICATION_HISTORY != null && MEDICATION_HISTORY.Length > 0) {
				for (int i = 0; i < MEDICATION_HISTORY.Length; i++) {
					segmentData.Add(MEDICATION_HISTORY[i].GetER7(options));
				}
			}
			if (PROBLEM != null && PROBLEM.Length > 0) {
				for (int i = 0; i < PROBLEM.Length; i++) {
					segmentData.Add(PROBLEM[i].GetER7(options));
				}
			}
			if (GOAL != null && GOAL.Length > 0) {
				for (int i = 0; i < GOAL.Length; i++) {
					segmentData.Add(GOAL[i].GetER7(options));
				}
			}
			if (PATHWAY != null && PATHWAY.Length > 0) {
				for (int i = 0; i < PATHWAY.Length; i++) {
					segmentData.Add(PATHWAY[i].GetER7(options));
				}
			}
			if (REL != null && REL.Length > 0) {
				for (int i = 0; i < REL.Length; i++) {
					segmentData.Add(REL[i].GetER7(options));
				}
			}
           segmentData.AddRange(GetZSegmentsER7(options));
		   return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }


    }
}

